package collection;

import java.util.ArrayList;
import java.util.List;

public class ListDemo2 {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list:"+list);//list:[one, two, three, four, five]
        list.add(3,"six");
        System.out.println("list"+list);//list[one, two, three, six, four, five]
        //add()下标为最后一个元素的下一个位置，相当于追加操作
        list.add(6,"seven");
        System.out.println("list:"+list);//list:[one, two, three, six, four, five, seven]
        list.remove(2);//删除指定下标的元素
        System.out.println("list:"+list);//list:[one, two, six, four, five, seven]

        String s=list.remove(1);//删除并返回指定下标的元素
        System.out.println(s);//two
        System.out.println("list:"+list);//list:[one, six, four, five, seven]
    }
}
